# Import libraries and modules
import numpy as np
import Synthesis as synt
import time
import Utils as ut
import TestCase as tc
from copy import deepcopy
from qiskit_textbook.tools import array_to_latex
# Testcase preparation
U = ut.generateRandomU(nq=4, nc=20) # Generate random matrix
#U = tc.u # or Use already manually generated matrises in TestCase.py
# Show input matrix
ut.matrix_to_latex(U)
# Check if the matrix is unitary (if so return True)
ut.checkUnitarity(U)
True
# Pass the matrix to synthesis function and call it, then save the return values
# The main return value is Clifford+T Circuit saved in cliffordTCirc variable
# The sceond return value is a higher level circuit made up of only controlled gates, saved in mcgCirc variable
# The third return value is high level components including only 2 level matrises only, saved in HLCs2 variable
# The last return value is high level components including both 2 and 1 level matrises, saved in HLCs12 variable
start_time = time.time()
cliffordTCirc, mcgCirc, HLCs2, HLCs12 = synt.syntCliffordTCircuit(deepcopy(U))
exe_time = time.time() - start_time # measure execution time
# Show high level componets, 1 and 2 level matrises
HLCs12
# Show high level matrises, only 2 level matrises(1 levels converted into 2 levels)
HLCs2
# Show the circuit(made of only controlled gates)
mcgCirc.draw()
# Evaluate mcg circuit
result = ut.assess(U, mcgCirc)[0]
# Show the result (True if the circuit is correct)
result
True
# show the circuit(made of only Clifford+T gates)
cliffordTCirc.draw()
# Evaluate Clifford+T circuit
# Uin is the input matrix (in numerical form)
# Uout is the actuall matrix of generated circuit (in numerical form)
result1,Uin,Uout = ut.assess(U, mcgCirc)
# Show the result (True if the circuit is correct)
result1
True
# Show input matrix
array_to_latex(Uin)
# Show the actuall matrix of generated circuit
# Now compare Uin and Uout visually
array_to_latex(Uout)
# Compare
# Uin == Uout
# number of clifford+T gates
len(cliffordTCirc.data)
5722
# synthesis execuation time(in seconds)
print(exe_time,'s')
10.194831848144531 s